#include<iostream>
#include<vector>
using namespace std;


class Solution {
public:
    int hIndex(vector<int>& citations) {
        vector<int> tmp(1010, 0);
        int maxCit = -1;
        for (auto citation : citations) {
            maxCit = max(citation, maxCit);
            tmp[citation]++;
        }
        int totalCount = 0;
        for (int i = maxCit + 5; i >= 0; i--) {
            totalCount += tmp[i];
            if (totalCount >= i) return i;
        }
        return -1;
    }
};